%****************************************************************
%** This is a file to generate the maximum and minimum of time **
%** dummies after the demeaning operation in Section 2.3       **
%** Created by Min-Hua Huang, Jan 25, 2012                     **
%****************************************************************
clear; clc; format shortG;
load HansfordGomez_Data.mat;
code=HansfordGomez_Data(:,2);
y=HansfordGomez_Data(:,27);
grandmeany=mean(y);
n=size(y,1); 
x0=[HansfordGomez_Data(:,26) HansfordGomez_Data(:,3) HansfordGomez_Data(:,25) HansfordGomez_Data(:,29) HansfordGomez_Data(:,11:23)];
grandmeanx0=mean(x0);
m=size(x0,2);
obs=(1:n)';
replicate=[y x0 code obs];
replicate=sortrows(replicate,19);
%****** Replicate xtreg ******
dmean=dmean1(replicate,19);
mean4a=[(replicate(:,1:18)-dmean) replicate(:,19:20)];
mean4a=sortrows(mean4a,20);
y=mean4a(:,1)+grandmeany;
xw=ones(n,m)*-999;
for i=1:1:m
    xw(:,i)=mean4a(:,i+1)+grandmeanx0(i);
end
fprintf('\nMaximum and Minimum of Time Dummies after the Demeaning Operation\n')
fprintf('\nMaximal Value=% 5.2f%%\n',max(max(xw(:,5:17))));
fprintf('Minimal Value=% 5.2f%%\n\n',min(min(xw(:,5:17))));